$(window).resize(function(){
  		var i = $('#videos').height();
  		var y = $('#videos').width();
  		$('#video').css('height',i - 35);
  		$('#video_img').css('height',i - 35);
  		$('#video_left').css('height',i - 35).css('line-height',i - 35 + 'px');
  		$('#video_right').css('height',i - 35).css('line-height',i - 35 + 'px');
  		$('#xian').css('margin-top',i - 35);
  	/*	var x = i / 894;
  		$('#video_text').css('height',500 * x);
  		$('#video_text').css('width',y);
  		$('#video_text_top').css('width',y);
  		$('#video_text_texts').css('width',1200 * x);
  		$('#video_text_texts_').css('width',1200 * x);
  		$('#video_text_related').css('width',1200 * x);
  		$('.video_text_texts').css('width',1200 * x);*/
});
$(function(){
	var rand = parseInt(Math.random()*5+1);
	$("#videos").attr("src","img/index-" + rand +".mp4");
	$('#videos').trigger('pause');
	$('#videos').trigger('play');
	if (rand == 1) {
		$('#video_text_tops').css('margin-top','0px');
		$('.video_text_texts').removeClass('video_text_texts_');
		$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
	} else if (rand == 2) {
		$('#video_text_tops').css('margin-top','-80px');
		$('.video_text_texts').removeClass('video_text_texts_');
		$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
	} else if (rand == 3) {
		$('#video_text_tops').css('margin-top','-160px');
		$('.video_text_texts').removeClass('video_text_texts_');
		$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
	} else if (rand == 4) {
		$('#video_text_tops').css('margin-top','-240px');
		$('.video_text_texts').removeClass('video_text_texts_');
		$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
	} else if (rand == 5) {
		$('#video_text_tops').css('margin-top','-320px');
		$('.video_text_texts').removeClass('video_text_texts_');
		$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
	}
	$('#video').mouseover(function(){
		if ($(this).hasClass('videoPlay')) {
			$('#videos').trigger('pause');
			$(this).removeClass('videoPlay');
		} else{
			$('#videos').trigger('play');
			$(this).addClass('videoPlay');
		}
	})
	$('#video').mouseout(function(){
		if ($(this).hasClass('videoPlay')) {
			$('#videos').trigger('pause');
			$(this).removeClass('videoPlay');
		} else{
			$('#videos').trigger('play');
			$(this).addClass('videoPlay');
		}
	})
	var sa = setInterval(function(){
		var video = document.getElementById('videos');
		//总时间
		var duration = video.duration;
      	//当前时间
       	var currentTime = video.currentTime;
       	//百分百
       	var percentage = currentTime / duration * 100;
       	$('#xian').css('width',percentage + '%');
		setInterval("","1000");
	},10);
    var md = document.getElementsByTagName("video")[0];
    md.addEventListener("ended",function(){
    	var rand = parseInt(Math.random()*5+1);
		if (rand == 1) {
			$('#video_text_tops').css('margin-top','0px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (rand == 2) {
			$('#video_text_tops').css('margin-top','-80px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (rand == 3) {
			$('#video_text_tops').css('margin-top','-160px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (rand == 4) {
			$('#video_text_tops').css('margin-top','-240px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (rand == 5) {
			$('#video_text_tops').css('margin-top','-320px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		}
        $("#videos").attr("src","img/index-" + rand +".mp4");
		$('#videos').trigger('pause');
		$('#videos').trigger('play');
    })
	$('#video_text_related span').mouseover(function(){
		$(this).css('background','rgba(0,0,0,0.8)');
	})
	$('#video_text_related span').mouseout(function(){
		$(this).css('background','rgba(0,0,0,0.5)');
	})
	$('#video_left').mouseover(function(){
		$(this).css('width','450px');
		$('#video_left span').css('opacity','1');
	})
	$('#video_left').mouseout(function(){
		$(this).css('width','350px');
		$('#video_left span').css('opacity','0.2');
	})
	$('#video_right').mouseover(function(){
		$(this).css('width','450px').css('margin-left','-450px');
		$('#video_right span').css('opacity','1');
	})
	$('#video_right').mouseout(function(){
		$(this).css('width','350px').css('margin-left','-350px');
		$('#video_right span').css('opacity','0.2');
	})
	$('#video_left').click(function(){
		var i = $('#video_text_tops').css('margin-top');
		if (i == '0px') {
			$("#videos").attr("src","img/index-5.mp4");
			$('#video_text_tops').css('margin-top','-320px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-80px') {
			$("#videos").attr("src","img/index-1.mp4");
			$('#video_text_tops').css('margin-top','0px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-160px') {
			$("#videos").attr("src","img/index-2.mp4");
			$('#video_text_tops').css('margin-top','-80px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-240px') {
			$("#videos").attr("src","img/index-3.mp4");
			$('#video_text_tops').css('margin-top','-160px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-320px') {
			$("#videos").attr("src","img/index-4.mp4");
			$('#video_text_tops').css('margin-top','-240px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		}
	})
	$('#video_right').click(function(){
		var i = $('#video_text_tops').css('margin-top');
		if (i == '0px') {
			$("#videos").attr("src","img/index-2.mp4");
			$('#video_text_tops').css('margin-top','-80px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-80px') {
			$("#videos").attr("src","img/index-3.mp4");
			$('#video_text_tops').css('margin-top','-160px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-160px') {
			$("#videos").attr("src","img/index-4.mp4");
			$('#video_text_tops').css('margin-top','-240px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-240px') {
			$("#videos").attr("src","img/index-5.mp4");
			$('#video_text_tops').css('margin-top','-320px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		} else if (i == '-320px') {
			$("#videos").attr("src","img/index-1.mp4");
			$('#video_text_tops').css('margin-top','0px');
			$('.video_text_texts').removeClass('video_text_texts_');
			$('.video_text_texts').eq(rand - 1).addClass('video_text_texts_');
		}
	})
	
});